package pl.edu.agh.gronoMining.owlToGraphConverter.parser.implementation;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import org.apache.log4j.Logger;

import pl.edu.agh.gronoMining.owlToGraphConverter.graph.Edge;
import pl.edu.agh.gronoMining.owlToGraphConverter.graph.Graph;
import pl.edu.agh.gronoMining.owlToGraphConverter.graph.Vertex;
import pl.edu.agh.gronoMining.owlToGraphConverter.parser.ISimpleSerializer;

public class ToGSpanSerializer implements ISimpleSerializer {

	private int graphId = 0;
	
	private static Logger logger = Logger.getLogger(SimpleSerializer1.class);
	
	@Override
	public void serialize(Graph[] graphs, OutputStream out) throws IOException {
		
		for (Graph g : graphs) {
			logger.info("Start serializing graph "+graphId);
			
			BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
			
			writer.write("t # " + graphId+"\n");
			writer.flush();
			graphId++;
			
			for (Vertex v : g.vertexSet()) {
				writer.write("v "+v.getNumber()+" "+v.getLabel()+"\n");
			}
			writer.flush();
			
			for (Edge e : g.edgeSet()) {
				writer.write("e "+e.getV1().getNumber()+" "+e.getV2().getNumber()+" 0\n");
			}
			//writer.write("\n");
			
			writer.flush();
		}
		
		logger.info("end serializing");

	}

}
